package com.shuzijun.leetcode.editor.cn;
public class DiaoZhengShuZuShunXuShiQiShuWeiYuOuShuQianMianLcof{
    public static void main(String[] args) {
         Solution solution = new DiaoZhengShuZuShunXuShiQiShuWeiYuOuShuQianMianLcof().new Solution();
         solution.exchange(new int[]{1,2,3,4});
    }
    //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
//    public int[] exchange(int[] nums) {
//        int i = 0;
//        int j = nums.length-1;
//        while (i <j){
//            if (nums[i]%2 == 1){
//                i++;
//                continue;
//            }
//            if (nums[j]%2 == 0){
//                j--;
//                continue;
//            }
//            int tmp = nums[i];
//            nums[i] = nums[j];
//            nums[j] = tmp;
//            i++;j--;
//        }
//        return nums;
//    }

        public int[] exchange(int[] nums) {
            int i = 0;
            int j = nums.length-1;
            while (i < j){
                if (nums[i] %2 == 1){
                    i++;
                    continue;
                }
                if (nums[j]%2 == 0){
                    j--;continue;
                }
                int tmp = nums[i];
                nums[i] = nums[j];
                nums[j] = tmp;

                i++;j--;
            }
            return nums;
        }
}
//leetcode submit region end(Prohibit modification and deletion)

}